package sleuthkit.gui;

import javax.swing.JTree;
import javax.swing.event.TreeExpansionEvent;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.DefaultTreeModel;
import javax.swing.tree.TreeNode;
import javax.swing.tree.TreePath;

import org.apache.log4j.Logger;

import sleuthkit.util.Node;
import sleuthkit.util.StaticHelper;
import sleuthkit.util.sleuthkit.processors.FlsProcessor;
import sleuthkit.util.sleuthkit.processors.Processor;

public class MyExplorerViewJTreeExpansionListener extends
		MyTreeExpansionListener {

	private Logger log = Logger.getLogger(MyExplorerViewJTreeExpansionListener.class) ;
	private Processor fls = new FlsProcessor();
	public MyExplorerViewJTreeExpansionListener() {
		StaticHelper.configLogger();
	}

	@Override
	public void treeCollapsed(TreeExpansionEvent event) {
		
	}

	@Override
	public void treeExpanded(TreeExpansionEvent event) {
		// TODO Auto-generated method stub
		log.debug("event.path = " + event.getPath().toString());
		TreePath path = event.getPath();
		log.debug("the last object in the path is " + path.getLastPathComponent());
		DefaultMutableTreeNode component = (DefaultMutableTreeNode) path.getLastPathComponent();
		Node userObject = (Node) component.getUserObject();
		log.debug("userObject = " + userObject);
		//if (userObject.isImageFile()){
			for (int i = 0,childCount = component.getChildCount();i<childCount;i++){
				log.debug("i = " + i + "; ChildCount = " + childCount);
				DefaultMutableTreeNode child = (DefaultMutableTreeNode) component.getChildAt(i);
				log.debug("child = " + child);
				userObject = (Node) child.getUserObject();
				log.debug("userObject = " + child.getUserObject());
				if (userObject.isPartitionEntry()){
					fls.process(userObject, child, userObject.getImageFile());
				}
			}
		//} else if (userObject.isDirectory())
	}

}
